@using BTCPayServer.Components.MainLogo
@using BTCPayServer.Services
@using BTCPayServer.Views.Server
@using BTCPayServer.Views.Stores
@inject BTCPayServerEnvironment Env
@model BTCPayServer.Components.StoreSelector.StoreSelectorViewModel
@functions {
    @* ReSharper disable once CSharpWarnings::CS1998 *@
	#pragma warning disable 1998
    private async Task LogoContent()
    {
        <vc:main-logo />
        @if (Env.NetworkType != NBitcoin.ChainName.Mainnet)
        {
            var type = Env.NetworkType.ToString();
            var displayType = type.Replace("Testnet", "TN").Replace("Regtest", "RT").Replace("Signet", "SN");
            <small class="badge bg-warning rounded-pill ms-1 ms-sm-0" title="@type">@displayType</small>
        }
    }
    private string StoreName(string title)
    {
        return string.IsNullOrEmpty(title) ? StringLocalizer["Unnamed Store"] : title;
    }
	#pragma warning restore 1998
}
@if (Model.CurrentStoreId == null)
{
    <a asp-controller="UIHome" asp-action="Index" id="StoreSelectorHome" class="navbar-brand py-2">@{await LogoContent();}</a>
}
else
{
    <a asp-controller="UIStores" asp-action="Index" asp-route-storeId="@Model.CurrentStoreId" id="StoreSelectorHome" class="navbar-brand py-2">@{await LogoContent();}</a>
}
@if (Model.Options.Any() || Model.ArchivedCount > 0)
{
    <div id="StoreSelector">
        <div id="StoreSelectorDropdown" class="dropdown only-for-js">
            <button id="StoreSelectorToggle" class="btn btn-secondary dropdown-toggle rounded-pill px-3 @(Model.CurrentStoreId == null ? "empty-state" : "")" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                @if (!string.IsNullOrEmpty(Model.CurrentStoreLogoUrl))
                {
                    <img class="logo" src="@Model.CurrentStoreLogoUrl" alt="@Model.CurrentDisplayName" />
                }
                else
                {
                    <vc:icon symbol="nav-store"/>
                }
                <span>@(Model.CurrentStoreId == null ? StringLocalizer["Select Store"] : Model.CurrentDisplayName)</span>
                <vc:icon symbol="caret-down"/>
            </button>
            <ul id="StoreSelectorMenu" class="dropdown-menu" aria-labelledby="StoreSelectorToggle">
                @foreach (var option in Model.Options)
                {
                    <li>
                        <a asp-controller="UIStores" asp-action="Index" asp-route-storeId="@option.Value" class="dropdown-item @(option.Selected && !ViewData.ContainsKey("StoreList") ? "active" : "")" id="StoreSelectorMenuItem-@option.Value">@StoreName(option.Text)</a>
                    </li>
                }
                @if (Model.Options.Any())
                {
                    <li><hr class="dropdown-divider"></li>
                }
                <li><a asp-controller="UIUserStores" asp-action="CreateStore" class="dropdown-item @(ViewData.ContainsKey("CreateStore") ? "active" : "")" id="StoreSelectorCreate" text-translate="true">Create Store</a></li>
                @if (Model.ArchivedCount > 0)
                {
                    <li><hr class="dropdown-divider"></li>
                    <li><a asp-controller="UIUserStores" asp-action="ListStores" asp-route-archived="true" class="dropdown-item @(ViewData.ContainsKey("ArchivedStores") ? "active" : "")" id="StoreSelectorArchived">@(Model.ArchivedCount == 1 ? StringLocalizer["{0} Archived Store", Model.ArchivedCount] : StringLocalizer["{0} Archived Stores", Model.ArchivedCount])</a></li>
                }
            </ul>
        </div>
    </div>
}
